package com.encryption.feature.user.ui.render
{
	import com.encryption.controls.confirm.ConfirmDialogPopUpManager;
	import com.encryption.controls.confirm.ConfirmTipDialog;
	import com.encryption.controls.loading.DelayPopUpManager;
	import com.encryption.controls.tip.TipShowManager;
	import com.encryption.feature.doc.ui.render.OperationLabel;
	import com.encryption.rpc.RPCEvent;
	import com.encryption.rpc.facade.RPCFacadeHelper;
	import com.encryption.rpc.facade.UserFacade;
	import com.encryption.rpc.model.User;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.controls.DataGrid;
	import mx.core.FlexGlobals;
	import mx.core.UIComponent;
	import mx.rpc.events.ResultEvent;
	
	public class UserDeleteOperationLabel extends UserOperationLabel
	{
		public function UserDeleteOperationLabel()
		{
			super();
			
			text = "删除";
		}
		
		override protected function mouseClickHandle(event:MouseEvent):void
		{
			var dialog:ConfirmTipDialog = ConfirmDialogPopUpManager.addPopUp(null, FlexGlobals.topLevelApplication as DisplayObject, 
				"您确定要删除" + user.toString() + "吗？", ensureToDelete);
			ConfirmDialogPopUpManager.centerPopUp(dialog);
		}
		
		private function ensureToDelete(event:Event):void
		{
			DelayPopUpManager.popUp("删除中...",FlexGlobals.topLevelApplication as UIComponent);
			new UserFacade(UserFacade.OPERATION_deleteUser, {arg0:user.id}, deleteUserHandle);
		}
		
		private function deleteUserHandle(event:RPCEvent):void
		{
			DelayPopUpManager.removeAllTips();
			RPCFacadeHelper.rpcHandle(event,function(rsEvent:ResultEvent):void{
				var parentObj:DisplayObjectContainer = owner;
				while(!(parentObj is DataGrid)){
					parentObj = parentObj.parent;
				}
				
				parentObj.dispatchEvent(new Event("userListChange"));
				TipShowManager.showMessageTip("删除成功");
			},"删除失败");
		}
	}
}